﻿namespace SQLiteCoreDB
{

    /// <summary>
    /// SC 泛型单例类，采用线程安全方式实现单例模式。
    /// </summary>
    /// <typeparam name="T">必须具有无参数构造函数的类型</typeparam>
    public class SC<T> where T : new()
    {
        static SC() { }

        private static object _mutex = new object();
        private static bool _initialized = false;

        private static T _instance;

        /// <summary>
        /// Instance 静态属性，返回类型T的单例实例
        /// </summary>
        public static T I
        {
            get
            {
                if (!_initialized)
                {
                    lock (_mutex)
                    {
                        if (!_initialized)
                        {
                            _instance = new T();
                            _initialized = true;
                        }
                    }
                }
                return _instance;
            }
        }
    }

}
